<html>
<head>
  <meta charset="utf-8">
  <title>已发送商品-微信发单后台</title>
  <!-- 在移动端不缩放 -->
      <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
      <!-- 新 Bootstrap 核心 CSS 文件 -->
    @include('public.style')
</head>


<body>

	@include('public.navbar')

 <div style="margin: 0 20px;">




<table id="demo" class="layui-table" lay-filter="test" lay-data="{height: 'full-200'}"></table>


<!-- <script type="text/html" id="barDemo">
  <a class="layui-btn" lay-event="edit">修改</a>
  <a class="layui-btn layui-btn-danger" lay-event="del">上移</a>
  <a class="layui-btn layui-btn-normal" lay-event="copy">下移</a>
  <a class="layui-btn layui-btn-normal" lay-event="top">置顶</a>
  <a class="layui-btn layui-btn-normal" lay-event="down">下架</a>
</script> -->
 </div>

	@include('public.script')

<script type="text/javascript">
layui.use('table', function(){
  var table = layui.table,form = layui.form;

  //第一个实例
  table.render({
    elem: '#demo',
	cellMinWidth: 50, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	//height:'full',
	height:750,
    url: '/user/get_list?status=1', //数据接口
    page: true ,//开启分页
	//toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
    cols: [[ //表头
		 {field: 'ID', title: 'ID', width:50, align: 'center'},
		 {
            field: 'goodsImage',
            title: '推广图',
			width:120,
			align: 'center',
            templet: function(d){
                return '<div><img id="'+d.ID+'tgimg" src="'+d.goodsImage+'" alt="" width="100px" height="100px" class="layui-upload-img" onclick="previewImg(this)"></div>';
            }
        },{
            field: 'sucai1',
            title: '素材1',
			width:120,
			align: 'center',
            templet: function(d){
				if(d.sucai1 !== null && d.sucai1 !== ""){
					return '<div><img id="'+d.ID+'tgimg" src="'+d.sucai1+'" alt="" width="100px" height="100px" class="layui-upload-img" onclick="previewImg(this)"></div>';
				}else{
					return '<div>无</div>';
				}

            }
        },{
            field: 'sucai2',
            title: '素材2',
			width:120,
			align: 'center',
            templet: function(d){
                if(d.sucai2 !== null && d.sucai2 !== ""){
                	return '<div><img id="'+d.ID+'tgimg" src="'+d.sucai2+'" alt="" width="100px" height="100px" class="layui-upload-img" onclick="previewImg(this)"></div>';
                }else{
                	return '<div>无</div>';
                }

            }
        },{
            field: 'sucai3',
            title: '素材3',
			width:120,
			align: 'center',
            templet: function(d){
                if(d.sucai3 !== null && d.sucai3 !== ""){
                	return '<div><img id="'+d.ID+'tgimg" src="'+d.sucai3+'" alt="" width="100px" height="100px" class="layui-upload-img" onclick="previewImg(this)"></div>';
                }else{
                	return '<div>无</div>';
                }

            }
        },
		{
		    field: 'docment',
			title: '文案',
			width: 280,
			align: 'center',
		    templet: function(d){
				d.docment = Base64.decode(d.docment);
		        return '<textarea id="' + d.ID + 'checkinfo" placeholder="商品文案" class="layui-textarea">' + d.docment + '</textarea>';
		        //return '<div>' + d.docment + '</div>';
		    }
		},{
		    field: 'upcment',
			title: '补刀',
			width: 280,
			align: 'center',
		    templet: function(d){
				if(d.upcment != null && d.upcment != ""){
					d.upcment = Base64.decode(d.upcment);
				}else{
					d.upcment = "";
				}

		        return '<textarea id="' + d.ID + 'checkinfo" placeholder="补刀段子" class="layui-textarea">' + d.upcment + '</textarea>';
		    }
		},
		{field: 'in_time', title: '添加时间', width:160, align: 'center'},
		{field: 'up_time', title: '发送时间', width:160, align: 'center'},
		//{field: 'L_phone', title: '手机号', width:100, align: 'center'},
		// {fixed: 'in_time', title:'上架时间', width:50, align: 'center'},
		// {fixed: 'up_time', title:'发送时间', width:50, align: 'center'},
		{fixed: 'right', title:'操作', toolbar: '#barDemo', width:50, align: 'center'}
		]]

  });


    //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
	console.log(data);
	var ID = data.ID;

    if(obj.event === 'down'){
		var statu = 0;
		//alert(uid);
	 layer.confirm('真的要下架么？', function(index){
	         obj.del();
	         layer.close(index);
			 del_goods(ID);
	       });



	}
else if(obj.event === 'edit'){

// layer.open({
//       type: 2,
//       title: '修改商品',
//       shadeClose: true,
//       shade: false,
//       maxmin: true, //开启最大化最小化按钮
// 	  scrollbar:true,//是否允许浏览器出现滚动条
//       //area: ['740px', '740px'],
//       content: 'iframe.php?uid='+uid
//     });
var index = layer.open({
  type: 2,
  title: '修改商品',
  shadeClose: true,
  shade: false,
  content: 'iframe.php?ID='+ID,
  area: ['320px', '195px'],
  maxmin: true
});
layer.full(index);


    }
else if(obj.event === 'copy'){
//layer.msg(sku_url + "<br>" + commise + "<br>"  + short_coupon);
var input = $('#'+uid+'box');
input.select();
document.execCommand("Copy");
layer.msg("复制文案成功！么么哒！");
	}
  });
});
</script>

<script>
	function del_goods(obj){

		$.get("../php/goods_up.php?ID="+obj, function(result){
		    layer.msg(result);
		  });
	}
    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        var height = img.height*2/3 + 50; //获取图片高度
        var width = img.width*2/3; //获取图片宽度
        var imgHtml = "<img width='" + width + "' height='" + height + "' src='" + obj.src + "' />";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [width + 'px',height+'px'],
            shadeClose:true,//点击外围关闭弹窗
            scrollbar: false,//不现实滚动条
           // title: "图片预览", //不显示标题
            title: false, //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }
</script>
<script>
	function check(obj){
		var uid = obj.id;
		var checkbox =  document.getElementById(uid+'checkbox').children(":first").innerhtml();

		alert(checkbox);

	}

	</script>
</body>
</html>
